package com.jxw.launcher;

import android.app.AlertDialog;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.jxw.engine.platsign.MainActivity;
import java.net.SocketException;

/* loaded from: classes.dex */
public class SnRepeatActivity extends BaseThemeActivity {
    public static final int ERROR_ALREADY_REGISTERD = 201;
    public static final int ERROR_OK = 200;
    public static final int ERROR_SERVER_ERROR = 100;
    public static final String PLATFORM = "A89S";
    Button btn_prregist;
    String exceptionMsg;
    EditText mInputSeries;
    String mcpuid;
    String serial;
    TextView tv_exceptionMsg;
    public static char[] chars = {'a', 'b', 'c', 'd', 'e', 'f', 'h', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};
    public static final int[] ERROR_STRING = {R.string.register_error_server_error, R.string.register_error_invalid_platform, R.string.register_error_invalid_series, R.string.register_error_invalid_device, R.string.register_error_series_used, R.string.register_error_device_used};

    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onBackPressed() {
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.jxw.launcher.BaseThemeActivity, com.jxw.launcher.BaseActivity, android.support.v4.app.FragmentActivity, android.support.v4.app.SupportActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_snrepeat);
        this.tv_exceptionMsg = (TextView) findViewById(R.id.tv_exceptionMsg);
        this.btn_prregist = (Button) findViewById(R.id.btn_prregist);
        this.mInputSeries = (EditText) findViewById(R.id.register_series);
        this.exceptionMsg = getIntent().getStringExtra("exceptionMsg");
        this.tv_exceptionMsg.setText(this.exceptionMsg);
        this.btn_prregist.setOnClickListener(new AnonymousClass1());
    }

    /* renamed from: com.jxw.launcher.SnRepeatActivity$1  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass1 implements View.OnClickListener {
        AnonymousClass1() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            if (!SnRepeatActivity.this.network()) {
                SnRepeatActivity.this.startActivity(new Intent("android.settings.WIFI_SETTINGS"));
                return;
            }
            SnRepeatActivity.this.btn_prregist.setEnabled(false);
            final String obj = SnRepeatActivity.this.mInputSeries.getText().toString();
            SnRepeatActivity.this.serial = MyApp.getInstance().getUserInfo();
            if ("".equals(SnRepeatActivity.this.serial)) {
                SnRepeatActivity snRepeatActivity = SnRepeatActivity.this;
                MyApp.getInstance();
                snRepeatActivity.serial = MyApp.getRKSerial();
            }
            SnRepeatActivity snRepeatActivity2 = SnRepeatActivity.this;
            MyApp.getInstance();
            snRepeatActivity2.mcpuid = MyApp.getCPUSerial();
            if (SnRepeatActivity.this.mcpuid != null && SnRepeatActivity.this.mcpuid.contains("000000000000000")) {
                SnRepeatActivity.this.mcpuid = null;
            }
            if (TextUtils.isEmpty(SnRepeatActivity.this.serial) && TextUtils.isEmpty(SnRepeatActivity.this.mcpuid) && (obj == null || obj.isEmpty())) {
                SnRepeatActivity snRepeatActivity3 = SnRepeatActivity.this;
                snRepeatActivity3.showDialog(snRepeatActivity3.getString(R.string.invalid_series));
                SnRepeatActivity.this.btn_prregist.setEnabled(true);
                return;
            }
            new Thread(new Runnable() { // from class: com.jxw.launcher.SnRepeatActivity.1.1
                @Override // java.lang.Runnable
                public void run() {
                    boolean z;
                    String str = null;
                    for (int i = 0; i < 5; i++) {
                        try {
                            str = MyApp.getInstance().macAddress();
                        } catch (SocketException e) {
                            e.printStackTrace();
                        }
                        if (str != null) {
                            break;
                        }
                    }
                    if (str == null) {
                        SnRepeatActivity.this.mInputSeries.post(new Runnable() { // from class: com.jxw.launcher.SnRepeatActivity.1.1.1
                            @Override // java.lang.Runnable
                            public void run() {
                                SnRepeatActivity snRepeatActivity4 = SnRepeatActivity.this;
                                snRepeatActivity4.showDialog(SnRepeatActivity.this.getString(R.string.register_fail) + SnRepeatActivity.this.getString(R.string.read_machineid_fail));
                                SnRepeatActivity.this.btn_prregist.setEnabled(true);
                            }
                        });
                    } else if (!TextUtils.isEmpty(obj)) {
                        try {
                            Long.parseLong(obj);
                            z = true;
                        } catch (Exception e2) {
                            e2.printStackTrace();
                            z = false;
                        }
                        String str2 = obj;
                        try {
                            if (!z) {
                                char c = 0;
                                for (int i2 = 0; i2 < obj.length() - 1; i2++) {
                                    c = (char) (c ^ obj.charAt(i2));
                                }
                                if (obj.charAt(obj.length() - 1) == SnRepeatActivity.chars[c % SnRepeatActivity.chars.length]) {
                                    str2 = MyApp.getInstance().getDeviceSerial();
                                }
                            } else if (str2.length() == 10) {
                                int charAt = obj.charAt(8) - '0';
                                int charAt2 = obj.charAt(1) - '0';
                                int charAt3 = obj.charAt(2) - '0';
                                int charAt4 = obj.charAt(3) - '0';
                                if ((obj.charAt(0) - '0') * 2 == charAt && Math.abs(charAt2 - charAt3) == charAt4) {
                                    str2 = MyApp.getInstance().getDeviceSerial();
                                }
                            }
                        } catch (Exception unused) {
                        }
                        final String register = MyApp.getInstance().register(1, "A89S", "00:e3:d9:78:07:eb", str2, "0xa53fe200", "", null);
                        SnRepeatActivity.this.mInputSeries.post(new Runnable() { // from class: com.jxw.launcher.SnRepeatActivity.1.1.2
                            @Override // java.lang.Runnable
                            public void run() {
                                Log.e(MainActivity.CERTIFICATION, register + "");
                                SnRepeatActivity.this.btn_prregist.setEnabled(true);
                                String[] parseResult = MyApp.getInstance().parseResult(register);
                                if (parseResult != null) {
                                    try {
                                        int parseInt = Integer.parseInt(parseResult[0], 10);
                                        if (parseInt >= 200 && parseInt <= 201) {
                                            if (MyApp.getInstance().saveCertification(parseResult[1])) {
                                                SnRepeatActivity.this.sendBroadcast(new Intent("com.zzj.regist_success"));
                                                SnRepeatActivity.this.finish();
                                            } else {
                                                SnRepeatActivity snRepeatActivity4 = SnRepeatActivity.this;
                                                snRepeatActivity4.showDialog(SnRepeatActivity.this.getString(R.string.register_fail) + SnRepeatActivity.this.getString(R.string.save_cert_fail));
                                            }
                                        } else {
                                            SnRepeatActivity snRepeatActivity5 = SnRepeatActivity.this;
                                            snRepeatActivity5.showDialog(SnRepeatActivity.this.getString(R.string.register_fail) + parseResult[0] + "(" + SnRepeatActivity.this.getErrorString(parseResult[0]) + ")");
                                        }
                                        return;
                                    } catch (NumberFormatException e3) {
                                        e3.printStackTrace();
                                        return;
                                    }
                                }
                                SnRepeatActivity snRepeatActivity6 = SnRepeatActivity.this;
                                snRepeatActivity6.showDialog(SnRepeatActivity.this.getString(R.string.register_fail) + SnRepeatActivity.this.getString(R.string.network_error));
                            }
                        });
                    } else {
                        SnRepeatActivity.this.mInputSeries.post(new Runnable() { // from class: com.jxw.launcher.SnRepeatActivity.1.1.3
                            @Override // java.lang.Runnable
                            public void run() {
                                SnRepeatActivity snRepeatActivity4 = SnRepeatActivity.this;
                                snRepeatActivity4.showDialog(SnRepeatActivity.this.getString(R.string.register_fail) + SnRepeatActivity.this.getString(R.string.invalid_series));
                                SnRepeatActivity.this.btn_prregist.setEnabled(true);
                            }
                        });
                    }
                }
            }).start();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public String getErrorString(String str) {
        int parseInt = Integer.parseInt(str);
        if (parseInt == 901) {
            return getString(R.string.register_error_invalid);
        }
        int[] iArr = ERROR_STRING;
        return getString(iArr[(parseInt - 100) % iArr.length]);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean network() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        connectivityManager.getNetworkInfo(0);
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void showDialog(String str) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(str);
        builder.setTitle("提示");
        builder.create().show();
    }
}
